package com.wa.controller.exceptions;
import com.wa.exceptions.TestResponseStatusException;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/exception")
public class ExceptionHandlerController {

	/**
	 * 	127.0.0.1:8080/exception/testSimpleMappingExceptionResolver?i=11
	 */
	@RequestMapping("/testSimpleMappingExceptionResolver")
	public String testSimpleMappingExceptionResolver(@RequestParam("i") int i){
		String [] vals = new String[10];
		System.out.println(vals[i]);
		return "success";
	}

	@RequestMapping(value="/testDefaultHandlerExceptionResolver",method= RequestMethod.POST)
	public String testDefaultHandlerExceptionResolver(){
		System.out.println("testDefaultHandlerExceptionResolver...");
		return "success";
	}

	@ResponseStatus(reason="测试responseStatus",value= HttpStatus.NOT_FOUND)
	@RequestMapping("/testResponseStatusExceptionResolver")
	public String testResponseStatusExceptionResolver(@RequestParam("i") int i){
		if(i == 13){
			throw new TestResponseStatusException();
		}
		System.out.println("testResponseStatusExceptionResolver...");

		return "success";
	}
	
}
